# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
#     https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
#     https://docs.fastlane.tools/plugins/available-plugins
#

# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

default_platform(:ios)

platform :ios do

  desc "打 ad-hoc 包"
  lane :Adhoc do |options|
  
    time = Time.new.strftime("%Y%m%d%H%M%S")

    ipa_name = "ealingmom_adhoc_#{time}.ipa"

    # 检查 git 是否有未提交状态
    ensure_git_status_clean

    git_pull

    # 自增 build 号,并 commit 相关 build 文件
    current_build_number = get_build_number_from_xcodeproj(
      xcodeproj: "XAPageViewDemo.xcodeproj",
      target: 'XAPageViewDemo')
    puts "current version #{current_build_number}"
    increment_build_number_in_xcodeproj
    commit_version_bump(
      message: "Machine Change Build",
    )

    #导出ipa的地址
    output_directory = options[:output_directory] ? options[:output_directory] : "./build/"

    # 导出的ipa名字
    output_name = options[:output_name] ? options[:output_name] : ipa_name

    # git 更新组件
    #sh "../YXLiveVideoApp/update_pods.sh"

    gym(
        workspace: "./XAPageViewDemo.xcworkspace",
        configuration: "Debug",
        scheme:"XAPageViewDemo",
        clean: true,
        silent: true,
        export_method: "ad-hoc",
        output_directory: output_directory,
        output_name: output_name,
        archive_path: "./archive/",
        export_options: {
          provisioningProfiles: { 
              "com.ealing.mom" => "ealingmom_adhoc"
           }
        },
      )
    
    fir_upload
  end


  desc "上传至 fir"
  lane :fir_upload do |options|
    firim(firim_api_token: "6839f0c01618415f205763b525725972")
  end

end
